var network = require('../utils/network_util.js');
var api = require('../utils/api.js');
var utils = require('../utils/utils.js');

//售后

function shouhouTk(type, e) {
  var order = e.currentTarget.dataset.order;
  var product = e.currentTarget.dataset.product;
  var linkType = e.currentTarget.dataset.order.linkType; //0,1，退钱  2，退积分
  var productprice = 0;
  var pspec = "";
  if (product.productSpec) {
    productprice = product.productSpec.price;
    pspec = product.productSpec.name + (product.productSpec.name1 ? ('+' + product.productSpec.name1) : '') + (product.productSpec.name2 ? ('+' + product.productSpec.name2) : '');
  } else {
    productprice = product.price;
  }
  var productprices = productprice * product.count;
  var saleMoney = order.oldSaleMoney;
  var integralPrice = order.oldIntegralPrice;
  var ordertotal = order.oldTotal + saleMoney + integralPrice;
  var refund_fee = utils.refund2(ordertotal, productprices, integralPrice, saleMoney);

  if (refund_fee > 0) {
    var datas = {};
    datas.productid = product.id;
    datas.pimgurl = product.smallImgUrl;
    datas.ptitle = product.title;
    datas.pcount = product.count;
    datas.conMode = product.conMode;
    datas.pprice = productprice;
    datas.pspec = pspec;
    datas.refund_fee = refund_fee;
    datas.linkType = linkType;
    wx.setStorageSync('product', datas);
    var orderid = e.currentTarget.dataset.order.id;
    var tktype = e.currentTarget.dataset.tktype; // 0=退款；1=退货退款

    if (type == 1) {
      wx.redirectTo({
        url: '/pages/myself/order/shouhou/tuikuan?orderid=' + orderid + '&tktype=' + tktype
      })
    } else {
      wx.navigateTo({
        url: '/pages/myself/order/shouhou/tuikuan?orderid=' + orderid + '&tktype=' + tktype
      })
    }
  } else {
    wx.showModal({
      title: '提示',
      content: '此订单不满足退款条件！',
    })
  }

}

module.exports = {
  shouhouTk: shouhouTk
}

